package com.customer.crm.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Lyp
 * @create 2021/12/15
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //登录成功后，应该有用户的 session
        Object systemUser = request.getSession().getAttribute("systemUser");
        if (systemUser == null){
            //没有登录
            response.sendRedirect("/login.html");
            return false;
        }else{
            return true;
        }
    }
}
